package horsegame;

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.io.File;
import java.io.IOException;



public class ceshi{

    class Position{

        public String horseinfo;
        public int num;
        public int x = 45;
        public Position(String horseinfo,int num){
            this.horseinfo = horseinfo;
            this.num = num;
        }
    }
        class MyPanel extends JPanel{
            private static final long serialVersionUID = 1L;

            private Image image = new ImageIcon("./src/Image/horse.gif").getImage();
            private Image hdoor = new ImageIcon("./src/Image/hdoor.png").getImage();
            private Image vdoor = new ImageIcon("./src/Image/vdoor.png").getImage();

            Position[]pos = new Position[4];
            public MyPanel() {
                for (int i = 0; i < pos.length; i++) {
                    pos[i] = new Position("第" + (i + 1) + "匹马", i + 1);
                }
            }

                @Override
                protected void paintComponent(Graphics g) {
                    // TODO Auto-generated method stub
                    super.paintComponent(g);
                    g.setColor(Color.GREEN);//更改面板为白色
                    g.fillRect(0,0,1000,600);
                    g.setFont(new Font("Segoe Print",Font.BOLD,40));
                    int yHeight = 40;
                    for (int i = 0; i < pos.length; i++) {
                        g.setColor(new Color(20,247,252));//先划数字要更改画笔颜色
                        g.drawString(pos[i].num+"", 5, 65+100*i);
                        g.setColor(Color.BLACK);
//				g.drawLine(0, 100*(i+1), 1000, 100*(i+1));用黑色划四条线
                        g.fillRect(0, 97+100*i, 1000, 3);//矩形
                        g.drawImage(image, pos[i].x,100*i,(int)(120*0.8),(int)(130*0.8), this);
                        g.drawImage(vdoor,140 , 100*i, null);
                }
                    g.setColor(Color.red);
                    g.fillRect(950, 0, 3, 400);
            }
    }

            private static final Font font = null;
    public ceshi(){
        JFrame frame = new JFrame("赛马");
        frame.setSize(1000,600);
        frame.setResizable(false);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setLayout(null);
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        frame.setLocation((screenSize.width-1000)/2,(screenSize.height-800)/2);



        try {
            Image image = ImageIO.read(new File("./src/Image/ahorse.png"));
            frame.setIconImage(image);
        } catch (IOException e){
            e.printStackTrace();
        }
        MyPanel panel = new MyPanel();
        panel.setBounds(0,0,1000,400);
        frame.add(panel);
        JPanel controlPanel = new JPanel();
        controlPanel.setBackground(Color.yellow);
        controlPanel.setBounds(0,400,1000,200);
        controlPanel.setLayout(null);//设置控制面板采用绝对布局 不采用浮动布局
        JLabel mesg = new JLabel("请选择一匹马:");//创建一个标签组件JLabel
        mesg.setBounds(5, 15, 120, 20);
        mesg.setFont(new Font("微软雅黑",Font.BOLD,15));
        controlPanel.add(mesg);
        ButtonGroup group = new ButtonGroup();
        for (int i = 0; i <4 ; i++) {
            JRadioButton radio = new JRadioButton((i+1)+"号");
            radio.setFont(new Font("微软雅黑",Font.BOLD,15));
            radio.setBounds(130+(i*50),15,50,20);
            radio.setBackground(Color.lightGray);
            group.add(radio);
            controlPanel.add(radio);
        }

        frame.add(controlPanel);
        
        frame.setVisible(true);
    }

    public static void main(String[] args) {
        new ceshi();
    }
}

